package com.rcadmin.busi.admin.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.rcadmin.busi.stat.dto.AppAccessDto;
import com.rcadmin.busi.stat.dto.AppMonthlyAccessDto;
import com.rcadmin.busi.stat.service.StatDailyAccessService;
import com.rcadmin.busi.web.service.TemplatePackageService;
import com.rcadmin.core.web.BaseAction;

/**
 * 
 * @author tanson lam
 * @create 2016年9月5日
 */
@Controller
public class MainController extends BaseAction {

	private static final String MAIN_PAGE = "/admin/main";
	@Resource
	private TemplatePackageService templatePackageService;
	@Resource
	private StatDailyAccessService statDailyAccessService;

	@GetMapping("/mainPage.op")
	public ModelAndView main() {
		Map<String, Object> dataModel = new HashMap<String, Object>();
		int templatePackageCount = templatePackageService
				.countEffTemplatePackage(getLoginUserId());
		AppMonthlyAccessDto appMonthlyAccess = statDailyAccessService
				.findByCurrentMonth(getLoginUserId());
		List<AppAccessDto> lastWeekAccess = statDailyAccessService
				.findLastWeekAndGroupApp(getLoginUserId());
		List<String> lastWeekList = statDailyAccessService.getLastWeekList();
		dataModel.put("lastWeekList", lastWeekList);
		dataModel.put("lastWeekAccess", lastWeekAccess);
		dataModel.put("templatePackageCount", templatePackageCount);
		dataModel.put("appMonthlyAccess", appMonthlyAccess);
		return render(MAIN_PAGE, dataModel);
	}
}
